package com.kmair.caiwu.controller.attendance;

import com.kmair.caiwu.attendance.pojo.Jiaban;
import com.kmair.caiwu.attendance.services.JiabanService;
import com.kmair.caiwu.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;


@Controller
@RequestMapping("/overtime")
public class OvertimeController extends BaseController {
    private final JiabanService dao;

    @Autowired
    public OvertimeController(JiabanService dao) {
        this.dao = dao;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String showJiaban(Model model) {
        List<Jiaban> jiabanList = dao.selectSelective(new Jiaban());
        model.addAttribute("jiabanList", jiabanList);
        model.addAttribute("jiaban", new Jiaban());
        return "attendance/overtime";
    }


    @RequestMapping(method = RequestMethod.POST)
    public String saveJiaban(Jiaban jiban) {
        jiban.setpYear(2017);
        dao.insert(jiban);
        dao.saveTotaljiabanDyas();
        return "redirect:/overtime";
    }


}
